package com.mzl.lal4cloud.lxw4rf.service.contract.exception;

import com.mzl.lal4cloud.lxw4rf.service.contract.bean.ErrorResult;

/**
 * @author J_luo
 */
public class ErrorException extends RuntimeException {
    private static final long serialVersionUID = 1L;

    private final ErrorResult errorResult;

    public ErrorException(String message) {
        this(ErrorResult.builder().code("-1").message(message).build());
    }

    public ErrorException(ErrorResult error) {
        super(error.toString());
        this.errorResult = error;
    }

    public ErrorException(ErrorResult error, Throwable cause) {
        super(error.toString(), cause);
        this.errorResult = error;
    }

    public ErrorException(Throwable cause) {
        super(cause.getMessage(), cause);
        this.errorResult = ErrorResult.builder().code("-1").message(cause.getMessage()).build();
    }

    public ErrorResult getError() {
        return this.errorResult;
    }
}
